package com.dada.controller;

import com.dada.domain.common.JsonResult;
import org.jooq.DSLContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.dada.domain.common.ApiConstants.APPLICATION_JSON;
import static com.dada.domain.common.JsonResult.ok;
import static com.dada.repository.DbConstants.DSL_TEST;

/**
 * Created by jianweilin on 16/9/5.
 */
@RestController
@RequestMapping(produces = APPLICATION_JSON)
public class RobotController {
    @Autowired
    @Qualifier(DSL_TEST)
    private DSLContext dsl;

    /**
     * 健康检查
     */
    @RequestMapping(value = "/alive")
    JsonResult alive() {
        return ok();
    }

    /**
     * 数据库测活连接
     */
    @RequestMapping(value = "/alive/db")
    JsonResult aliveDb() {
        return ok(dsl.selectCount().fetchOneInto(Integer.class));
    }
}
